/**
 * Copyright (c) 2024-2025 National Fundamental Software of China Co., Ltd.
 *
 * You should have find a copy of NFSChina License. If not, please contact us
 * by email <os_support@nfschina>
 *
**/

/*
    SPDX-FileCopyrightText: 2020 Tobias Fella <fella@posteo.de>

    SPDX-License-Identifier: GPL-2.0-or-later
*/

import QtQuick 2.12
import QtQuick.Controls 2.12 as QQC2

import org.kde.kirigami 2.7 as Kirigami


Rectangle {
    id: comboBoxItem

    border.color: form.bordercolor
    color:form.backgroundcolor// 背景颜色设置为白色
    radius: 10 // 设置圆角半径
    border.width: 1
    width: 558
    height: 48
    property string label
    // Kirigami.FormData.label: label
    property var component
    // 背景颜色


    Text{
        id: labelText
        leftPadding: 25
        anchors.centerIn: parent.left
        anchors.verticalCenter: parent.verticalCenter
        text: label
        font.family: "SourceHanSansSC-Regular"
        color: form.textcolor
    }
    QQC2.ComboBox {
        id: comboBox
        anchors.left: parent.horizontalCenter
        anchors.verticalCenter: parent.verticalCenter
        model: component.applications
        width:240
        height:30
        textRole: "name"
        currentIndex: component.index
        onActivated: component.select(currentIndex, true)
        
        delegate: QQC2.ItemDelegate {
            width: comboBox.popup.width
            text: modelData[comboBox.textRole]
            highlighted: comboBox.highlightedIndex == index
            icon.name: modelData.icon
        }
        
        // HACK QQC2 doesn't support icons, so we just tamper with the desktop style ComboBox's background
        Component.onCompleted: {
            if (!background || !background.hasOwnProperty("properties")) {
                //not a KQuickStyleItem
                return;
            }

            var props = background.properties || {};

            background.properties = Qt.binding(function() {
                var newProps = props;
                newProps.currentIcon = component.applications[currentIndex]["icon"];
                newProps.iconColor = Kirigami.Theme.textColor;
                return newProps;
            });
        }
    }



}





